package com.ruoyi.dynamic.controller.app;


import com.ruoyi.common.core.annotation.valid.group.ValidGroup;
import com.ruoyi.common.core.constant.constant.PathConstant;
import com.ruoyi.common.core.context.SecurityContextHolder;
import com.ruoyi.common.core.pojo.result.Pages;
import com.ruoyi.common.core.pojo.vo.BaseVO;
import com.ruoyi.common.core.pojo.vo.PageVO;
import com.ruoyi.common.core.pojo.vo.SingleVO;
import com.ruoyi.common.core.result.Result;
import com.ruoyi.dynamic.model.pojo.entity.LuckyBagUser;
import com.ruoyi.dynamic.model.pojo.request.app.*;
import com.ruoyi.dynamic.model.pojo.result.app.AppLuckyBagInfoResult;
import com.ruoyi.dynamic.service.ILuckyBagService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@Tag(name = "App-福袋相关", description = "App-福袋相关")
@RestController
@RequestMapping(PathConstant.APP_PATH + "lucky-bag")
public class AppLuckyBagController {


    private final ILuckyBagService luckyBagService;

    public AppLuckyBagController(ILuckyBagService luckyBagService) {
        this.luckyBagService = luckyBagService;
    }

    @Operation(summary = "发布福袋", description = "发布福袋")
    @PostMapping("issue")
    public BaseVO issue(@RequestBody @Validated(ValidGroup.Insert.class) AppCreateLuckBagRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        return Result.successOrFail(luckyBagService.release(request, userId));
    }


    @Operation(summary = "编辑福袋", description = "编辑福袋")
    @PostMapping("update")
    public BaseVO update(@RequestBody @Validated(ValidGroup.Insert.class) AppCreateLuckBagRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        return Result.successOrFail(luckyBagService.updateLuck(request, userId));
    }

    @Operation(summary = "福袋列表", description = "福袋列表")
    @GetMapping("listPage")
    public PageVO<AppLuckyBagInfoResult> listPage(@ParameterObject AppLuckBagSearchRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        Pages<AppLuckyBagInfoResult> pages = luckyBagService.listPage(request, userId);
        return Result.page(pages);
    }

    @Operation(summary = "福袋历史存模板", description = "福袋历史存模板")
    @PostMapping("save-tem")
    public BaseVO saveTem(@RequestBody @Validated(ValidGroup.Insert.class) AppRoomVoteMusicTemRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        return Result.successOrFail(luckyBagService.saveTem(request, userId));
    }

    @Operation(summary = "福袋详情", description = "福袋详情")
    @GetMapping("info")
    public SingleVO<AppLuckyBagInfoResult> info(Long id) {
        AppLuckyBagInfoResult result = luckyBagService.info(id, SecurityContextHolder.getUserId());
        return Result.single(result);
    }

    @Operation(summary = "福袋参与", description = "福袋弹幕参与")
    @PostMapping("comment")
    public BaseVO comment(@RequestBody @Valid AppLuckyBagCommentRequest request) {
        boolean add = luckyBagService.comment(request, SecurityContextHolder.getUserId());
        return Result.successOrFail(add);
    }

    @Operation(summary = "福袋参与人员列表", description = "福袋参与人员列表")
    @GetMapping("userListPage")
    public PageVO<LuckyBagUser> userListPage(@ParameterObject @Valid AppLuckyBagUserSearchRequest request) {
        Pages<LuckyBagUser> luckyBagUserPages = luckyBagService.userListPage(request);
        return Result.page(luckyBagUserPages);
    }

}

